package com.rabbitmq.ChattingRoom.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rabbitmq.ChattingRoom.service.RoomService;
import com.rabbitmq.ChattingRoom.service.mapper.RoomMapper;
import com.rabbitmq.ChattingRoom.util.Entity.Room;
import com.rabbitmq.ChattingRoom.util.Entity.User;
import com.rabbitmq.ChattingRoom.util.Entity.UserRoomMapping;
import com.rabbitmq.ChattingRoom.util.common.req.GetMsgReq;
import com.rabbitmq.ChattingRoom.util.common.req.HistoryMSGReq;
import com.rabbitmq.ChattingRoom.util.common.resp.RoomRESP;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoomServiceImpl implements RoomService {

    @Autowired
    private RoomMapper roomMapper;

    @Override
    public Integer addRoom(Room room) {
        return roomMapper.insert(room);
    }

    @Override
    public boolean isExistId(Long id) {
        QueryWrapper<Room> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(Room::getId,id);
        return roomMapper.selectCount(queryWrapper) > 0;
    }

    @Override
    public List<RoomRESP> getRoomsByUser(Long userId) {
        return roomMapper.getRoomsByUser(userId);
    }

    @Override
    public List<Room> getRooms(Integer status) {
        QueryWrapper<Room> queryWrapper = new QueryWrapper();
        queryWrapper.lambda().eq(Room::getRoomStatus,status);
        return roomMapper.selectList(queryWrapper);
    }

    @Override
    public Integer delRoomByUser(Room record) {
        return roomMapper.delRoomByUser(record);
    }

    @Override
    public List<HistoryMSGReq> getMsgByCount(GetMsgReq req) {
        return roomMapper.getMsgByCount(req);
    }

    @Override
    public Long getRoomCreaterByRoomId(Long roomId) {
        return roomMapper.getRoomCreaterByRoomId(roomId);
    }

}
